import Ember from 'ember';
import PatchFieldMixin from 'emberworkspace/mixins/patch-field';
import FormState from 'emberworkspace/utils/form-state';
import ItemViewMinxin from 'emberworkspace/mixins/item-view-mixin';

export default Ember.Controller.extend(PatchFieldMixin, ItemViewMinxin, {
  pageTitle: "树结构管理",
  pageSubTitle: "编辑树",
  modelName: "tree",
  autoBack: {
    create: true,
    edit: true
  },
  formState: FormState.create({
    btnName: "保存",
    successMsg: "成功",
    failMsg: "失败"
  }),
  menus: Ember.computed('model', function() {
    var model = this.get('model');
    if (model.isNew) {
      return [this.commonMenus[0]];
    } else {
      return [this.commonMenus[0], {
        name: "treenode",
        action: "treenode",
        label: "编辑树节点",
        showWhen: "always"
      }, this.commonMenus[1]];
    }
  }),
  actions: {
    submitForm() {
        this.defaultFromHandler();
      },
      menuClicked(mname) {
        if (mname === 'treenode') {
          var model = this.get('model');
          this.transitionToRoute("treenodes", model);
        } else {
          this.defaultMenuHandler(mname);
        }
      },
      nameFocused() {
        this.set('curfn', "树名称");
      },
      localedNameFocused() {
        this.set('curfn', "本地化树名称");
      },
      descriptionFocused() {
        this.set('curfn', "树描述");
      }
  }
});
